package com.example.demo.sys.service.bo;

import com.example.demo.sys.entity.UserProfile;
import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.BeanUtils;

@Data
public class UserProfileBO {
    private Long id;
    private Long userId;
    private String avatar;
    private String nickname;
    private String desc;
    private String org;
    private String title;
    private String dept;
    private List<String> tags;
    private String location;
    private String email;
    private Long createdAt;
    private Long updatedAt;
    public static UserProfileBO convert(UserProfile item) {
        if (item == null) {
            return null;
        }
        UserProfileBO result = new UserProfileBO();
        result.setId(item.getId());
        result.setUserId(item.getUserId());
        result.setAvatar(item.getAvatar());
        result.setNickname(item.getNickname());
        result.setDesc(item.getDesc());
        result.setDept(item.getDept());
        result.setOrg(item.getOrg());
        result.setEmail(item.getEmail());
        result.setTitle(item.getTitle());
        if(item.getTags()!=null) {
            result.setTags(Arrays.asList(item.getTags().split(",")));
        }
        result.setLocation(item.getLocation());

        return result;
    }

    public static UserProfile entity(UserProfileBO item) {
        if (item == null) {
            return null;
        }
        UserProfile result = new UserProfile();
        result.setId(item.getId());
        result.setUserId(item.getUserId());
        result.setAvatar(item.getAvatar());
        result.setNickname(item.getNickname());
        result.setDesc(item.getDesc());
        result.setDept(item.getDept());
        result.setOrg(item.getOrg());
        result.setTitle(item.getTitle());
        result.setEmail(item.getEmail());
        result.setTags(String.join(",", item.getTags()));
        result.setLocation(item.getLocation());

        return result;
    }
}
